import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Login',
    component: () => import('../views/Login.vue')
  }, 
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/Register.vue')
  }, 
  {
    path:'./home',
    name:'Home',
    redirect: {name: "User"},
    component: Home,
    children: [
      {
        path: '/sale',
        name: 'Sale',
        component: () => import('../views/Sale.vue')
      }, 
      {
        path: '/user',
        name: 'User',
        component: () => import('../views/User.vue')
      }, 
      {
        path: '/request',
        name: 'Request',
        component: () => import('../views/Request.vue')
      },
      {
        path: '/address',
        name: 'Address',
        component: () => import('../views/Address.vue')
      }, 
      {
        path: '/pinglun',
        name: 'Pinglun',
        component: () => import('../views/Pinglun.vue')
      }, 
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router